<!--
 * @Author: wangming
 * @Date: 2022-04-22 16:51:10
 * @LastEditors: wangming
 * @LastEditTime: 2022-04-22 17:17:29
 * @FilePath: /hanma-application-designer-fed/src/pages/designUniversal/__components__/dynamicForm/rightModel/components/hmChildConfig/__components__/addcode/template.vue
 * @Description: 
-->
<!--
 * @Author: wangming
 * @Date: 2020-09-09 14:04:55
 * @LastEditors: wangming
 * @LastEditTime: 2022-01-07 14:43:25
 * @Description:添加类别按钮
-->
<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="460px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>关联字段映射表</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>
    <el-form
      class="pl30 pr30"
      :model="FormData"
      ref="Form"
      label-width="120px"
      :rules="rules"
    >
      <el-form-item label="关联字段" prop="chidlrenKey">
        <el-select
          v-model="FormData.chidlrenKey"
          placeholder="请选择"
          size="small"
          class="mb10"
          value-key="code"
          style="width: 100%"
        >
          <el-option
            v-for="(item, index) in modelList"
            :key="index"
            :label="item.name"
            :value="item.code"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="主表映射字段" prop="parentCode">
        <el-select
          v-model="FormData.parentCode"
          placeholder="请选择"
          size="small"
          class="mb10"
          value-key="code"
          style="width: 100%"
        >
          <el-option
            v-for="(item, index) in myEntitymodelList"
            :key="index"
            :label="item.name"
            :value="item.code"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button @click="showVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { cloneDeep } from "lodash";
export default {
  data() {
    return {
      rules: {
        chidlrenKey: [
          { required: true, message: "请选择子表字段", trigger: "change" },
        ],
        parentCode: [
          { required: true, message: "请选择主表映射字段", trigger: "change" },
        ],
      },
      FormData: {
        chidlrenKey: "", //子表字段
        parentCode: "", //主表映射字段
      },
      showVisible: false,
      callback: () => {},
      myEntitymodelList: [],
      modelList: [],
    };
  },
  methods: {
    editForm({ myEntitymodelList, modelList }, FormData) {
      this.myEntitymodelList = myEntitymodelList;
      this.modelList = modelList;
      this.FormData = cloneDeep(FormData);
      return this.showModel();
    },
    addForm({ myEntitymodelList, modelList }) {
      this.myEntitymodelList = myEntitymodelList;
      this.modelList = modelList;
      this.FormData = {};
      return this.showModel();
    },
    showModel() {
      this.showVisible = true;
      this.$nextTick(() => {
        this.$refs.Form.clearValidate();
      });
      return {
        then: (callback) => {
          if (typeof callback === "function") {
            this.callback = callback;
          }
        },
      };
    },
    async submit() {
      try {
        await this.$refs.Form.validate();
        this.showVisible = false;
        this.callback(this.FormData);
      } catch (error) {}
    },
  },
};
</script>

<style lang="scss" scoped>
.max {
  width: 220px;
}
</style>
